package com.lanlian.cayman.utils;

import android.graphics.Color;
import android.widget.TextView;

import com.lanlian.cayman.LLApplication;
import com.lanlian.commonlib.dao.DBManager;
import com.lanlian.cayman.R;

public class MResUtil {

    private static int COLOR_UP = LLApplication.getInstance().getResources().getColor(R.color.color_T7);
    private static int COLOR_DOWN = LLApplication.getInstance().getResources().getColor(R.color.color_T8);
    private static int COLOR_PING = LLApplication.getInstance().getResources().getColor(R.color.color_text_style1);

    private static int COLOR_UP_BACK = R.drawable.bg_kline_up_back;
    private static int COLOR_DOWN_BACK = R.drawable.bg_kline_down_back;
    private static int COLOR_PING_BACK = R.drawable.bg_kline_ping_back;

    public static int getUpBack() {
        int a = DBManager.getInstance().getKLineColor();
        if (a == 1) {
            return COLOR_UP_BACK;
        } else {
            return COLOR_DOWN_BACK;
        }
    }

    public static int getDownBack() {
        int a = DBManager.getInstance().getKLineColor();
        if (a == 1) {
            return COLOR_DOWN_BACK;
        } else {
            return COLOR_UP_BACK;
        }
    }

    public static int getPingBack() {
        return COLOR_PING_BACK;
    }

    /**
     * 1红涨绿跌2绿涨红跌
     *
     * @return
     */
    public static int getColorType() {
        int a = DBManager.getInstance().getKLineColor();
        if (a == 1) {
            return 1;
        } else {
            return 2;
        }
    }

    public static int getUpColor() {
        int a = DBManager.getInstance().getKLineColor();
        if (a == 1) {
            //return COLOR_UP;
            return LLApplication.getInstance().getResources().getColor(R.color.color_T7);
        } else {
            //return COLOR_DOWN;
            return LLApplication.getInstance().getResources().getColor(R.color.color_T8);
        }
    }

    public static int getDownColor() {
        int a = DBManager.getInstance().getKLineColor();
        if (a == 1) {
            return LLApplication.getInstance().getResources().getColor(R.color.color_T8);
        } else {
            return LLApplication.getInstance().getResources().getColor(R.color.color_T7);
        }
    }

    public static int getPingColor() {
        if (DBManager.getInstance().getTopicColor() == 1) {
            return Color.parseColor("#101010");
        } else {
            return Color.parseColor("#d8dde8");
        }
    }

    /**
     * @param tv
     * @param type 小于0 等于0 大于0
     */
    public static void setColor(TextView tv, int type) {
        if (type < 0) {
            tv.setTextColor(getDownColor());
        } else if (type == 0) {
            tv.setTextColor(LLApplication.getInstance().getResources().getColor(R.color.color_text_style10));
        } else {
            tv.setTextColor(getUpColor());
        }
    }

}
